<template>
  <div class="selector-wrap">
    <mu-popup position="bottom" popupClass="demo-popup-bottom" :open="option.show" @close="close">
      <mu-list class="bgwhite text-center">
          <div class="popup-title">{{option.title}}</div>
          <template v-for="(item, i) in option.data">
            <mu-list-item :title="item.label" :key="i" @click="handleItemClick(item)"> 
            </mu-list-item>
            <mu-divider :key="i"/>
          </template>
      </mu-list>
      <div class="popup-footer" @click="close">取消</div>
    </mu-popup>
    </div>
</template>

<script>
export default {
  name: 'selector',
  props: {
    option: {
      type: Object,
      default: {
        show: false,
        title: '请选择',
        data: []
      }
    }
  },
  methods: {
    close () {
      this.option.show = false
    },
    handleItemClick (item) {
      this.$emit('change', item)
      this.close()
    }
  }
}
</script>

<style lang="less">
@import '../common/css/vars.less';
.demo-popup-bottom {
  width: 100%;
  .mu-item-title {
    text-align: center;
    color: @color-primary;
  }
}
.popup-title {
  text-align: center;
  line-height: 40px;
  color: #999;
  border-bottom: 1px solid @color-border;
}
.popup-footer {
  text-align: center;
  line-height: 40px;
  color: #666;
  border-top: 1px solid @color-border;
}
</style>
